A nonvolatile memory is a memory in which stored data is preserved even when supply of electric power is cut off. Therefore, the nonvolatile memory is referred to as a content-holding type of memory. A nonvolatile memory is commonly provided with a plurality of blocks which is a unit for performing writing and erasing data. Each of the respective blocks comprises a write data area for principally storing data and an inspection data area for inspecting the validity of data written in the write data area and storing inspection data obtained in the inspection. Further, for example, in the case of an EEPROM among nonvolatile memories, one block is often provided with a capacity of 16 bytes, which is allocated in an inspecting data area with one or two bytes and in a write data area with remaining bytes. An address specifying its location is added to the respective bytes.
Specifically, the inspection data area is provided with a BCC (Block Check Character) and a flag to judge whether the data stored in the write data area is accurately stored or not, i.e., the validity of stored data.
In such a nonvolatile memory, for example in the flash memory shown in Japanese Patent Laid-Open No. 2000-105694, a history showing that updating processing has been finished is recorded in a flag area in the respective blocks whenever respective steps of the updating processing have been finished. The flag area includes, for example, “rewriting start flag”, “rewriting finish flag”, “verify error flag”, “verify finish flag”, “erasure finish flag” and the like. Flag areas with the above-mentioned respective flags are confirmed at the time of starting of programs to confirm whether updating processing is normally performed at a predetermined position and to detect which step of the processing is discontinued. In this manner, an error in the overwriting processing for the respective blocks is prevented. Therefore, the error in the updating processing can be checked at a plurality of points from the history recorded in the flag areas and thus malfunction of the program can be prevented.
However, for example, data handled in a financial terminal such as a card reader is important data. Therefore, encryption processing may be performed on data transmitted from a host computer to enhance security and, in this case, key data used in the encryption processing may be stored in a nonvolatile memory. In recent years, the data length of the key data has become longer to further enhance the security. Therefore, the data may become larger than the capacity of the write data area and thus the data cannot be stored in one block. As a result, the data are divided into a plurality of blocks to be stored.
In the case that the data are divided and stored into a plurality of blocks, when a problem such as interruption of power supply occurs during updating of the data and the updating is interrupted, all of the blocks may not be updated. Specifically, the following cases may occur:                1. the updating is interrupted in the middle of rewriting of the data in the respective blocks.        2. the updating is interrupted between two blocks. In other words, new data is recorded in one block but other remaining blocks are not be rewritten and remain in a state with old data. Both cases are errors in the updating processing.        
In the flash memory described in the above-mentioned prior art, an error can be detected when updating is interrupted in the middle of rewriting the data in the above-mentioned respective blocks. However, in the above-mentioned prior art, whenever each of the respective steps of the updating processing has been finished in one block, a history indicating the finish of the respective steps is recorded in the flag area and thus it cannot be detected whether the data stored in the respective blocks is new data or old data. In other words, in the case that data is divided and stored into a plurality of blocks, an error cannot be detected when updating is interrupted between the updated block and the next block to be updated as described in the above-mentioned the case number 2. Therefore, when the interruption of power supply occurs during updating processing, the block where data is updated may coexist with the block where old data is stored.
In addition, in a card reader provided with the flash memory described in the above-mentioned prior art, a plurality of blocks where new data and old data coexist cannot be detected as described above and thus the card reader may be activated. Therefore, an abnormality is noticed only after a card has been inserted into a card reader and the card reader has been actually operated. Accordingly, the entire system including the card reader is required to be stopped and thus a user, for example a card holder may be subjected to a malfunction.